package com.example.controller;

import com.example.pojo.User;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class Hello2Controller {
    // 传统url传参 及 参数名指定(同名无需注解指定 /hello2?id=10&name=Alan)
    @GetMapping("/hello2")
    public String hello2(int id, @RequestParam("name") String userName,Model model) {

        model.addAttribute("id", "ID: " + id);
        model.addAttribute("name", "UserName: "+userName);

        return "hello2";
    }

    @GetMapping("/hello3")
    // 用对象参数接收需url中的参数名和属性名一致 "/hello3?id=100&name=Alan&birthDate=2000-01-01"
    public String hello3(User user, Model model){
        System.out.println(user);
        model.addAttribute("user", user);
        return "hello2";
    }
    
}
